Skip to content

feat(webhooks): add secure webhooks engine with rate limiting and configurable integrations - #405

Closed
DibashSarkar wants to merge 2 commits into
ArnasDon:mainfrom
DibashSarkar:feat/generic-webhooks
Closed

feat(webhooks): add secure webhooks engine with rate limiting and configurable integrations#405
DibashSarkar wants to merge 2 commits into
ArnasDon:mainfrom
DibashSarkar:feat/generic-webhooks

Conversation

@DibashSarkar

Copy link
Copy Markdown

Description

This PR introduces the core Generic Webhooks engine, allowing external integrations to trigger workflows. Following the previous review, this branch addresses all requested security enhancements, migration ordering, and WhatsApp API routing logic.

Note: This is the final part of splitting up the previous monolithic PR.

Key Changes & Review Feedback Addressed

  • Marketing Endpoint Routing: Addressed the assumption that all accounts are enrolled in Meta's Marketing Messages Lite API. Gated the /marketing_messages endpoint behind a new use_marketing_endpoint config flag on the whatsapp_config table (configurable via the UI). It now safely falls back to /messages for standard accounts.
  • Webhook Security (HMAC): Implemented cryptographic signature verification in the webhook receiver. Integrations now require an HMAC Secret to validate incoming requests, preventing unauthorized execution.
  • Webhook Rate Limiting: Added basic rate-limiting (src/lib/rate-limit.ts) to cap incoming webhooks at 60 requests per minute per workflow, preventing abuse.
  • Configurable Phone Prefix: Removed the hardcoded 91 country code. The default country code prefix is now fully configurable via the database and Webhooks UI settings.
  • Clean Migration Sequence: All custom migrations on this branch have been correctly re-sequenced (038 through 041) to start immediately after the latest upstream migrations, preventing any collision with upstream's 036.
  • UI Polish: Renamed placeholder bot names in the live WhatsApp preview to a generic "WhatsApp Bot".

Testing

  • Webhook endpoints correctly reject requests with invalid or missing HMAC signatures.
  • Rate limiting correctly throttles requests exceeding 60/min.
  • Meta API routing correctly respects the use_marketing_endpoint flag in integration tests.
  • All 664 unit tests run and pass without regressions (npm run test).
  • TypeScript compiles cleanly (npm run typecheck).

@DibashSarkar
DibashSarkar requested a review from ArnasDon as a code owner July 17, 2026 20:52
@ArnasDon

Copy link
Copy Markdown
Owner

Closing — this is a feature rather than a fix, and a large one: a second src/lib/generic-webhooks/ alongside the existing src/lib/webhooks/, an inbound webhook workflow engine, a new dashboard section and sidebar entry, and four migrations (one of which bundles marketing gating in with the webhook fields). It also touches middleware.ts, use-auth, use-realtime, send-message, meta-api and broadcast-core.

That's the case CONTRIBUTING.md describes as belonging in a fork. Inbound webhooks are a fair thing to want, though — if you'd like to make the case for them upstream, an issue is the right place to start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants